<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>
<%
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ request.getContextPath();
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
 		<link rel="stylesheet" type="text/css" href="<%=basePath %>/css/updateVideo.css" />
        <link rel="stylesheet" href="<%=basePath %>/css/list.css">
		<link href="<%=basePath %>/css/H-ui.min.css" rel="stylesheet" type="text/css" />
		<link href="<%=basePath %>/css/formsCSS.css" rel="stylesheet" type="text/css" />
		<script src="<%=basePath%>/lib/My97DatePicker/WdatePicker.js"></script>
		<script src="<%=basePath %>/js/jquery.min.js"></script>
		<script src="<%=basePath %>/js/formsJS.js"></script>

<script type="text/javascript">

function checkForm(f){

	if(f.adTitle.value.replace(/\s/g,'') == ''){
		alert("广告标题不能为空");
		$("#adTitle").focus();
		return false;
	}
	if(f.adStatus.value.replace(/\s/g,'') == ''){
		alert("广告状态不能为空");
		return false;
	}
	if(f.adStartTime.value.replace(/\s/g,'') == ''){
		alert("广告开始时间不能为空");
		$("#adStartTime").focus();
		return false;
	}
	if(f.adEndTime.value.replace(/\s/g,'') == ''){
		alert("广告结束时间不能为空");
		$("#adEndTime").focus();
		return false;
	}
	
	if(f.adType.value.replace(/\s/g,'') == ''){
		alert("广告类型不能为空");
		return false;
	}
	
	var h5Url = f.h5File.value;
	if(h5Url.replace(/\s/g,'') != ''){
		var fileLx = h5Url.toString().substring(filePath.toString().lastIndexOf(".")+1);
		if(fileLx == "zip"){
			return true;
		}else{
			alert("只能上传zip包");
			return false;
		}
	}
	if('${type}'=='add'){
		if(f.imgFile.value.replace(/\s/g,'') == ''){
			alert("广告图片不能为空");
			return false;
		}
	}


	return true;
}

//选中下拉框选择的值
function choice(){
	var adType = document.getElementById('adType').value.trim();  
	 
	 if(adType==1){
   		 $("#h5File").show();
  		 $("#courseId").hide();
  		$("#goodsId").hide();
  		$("#cardId").hide();
  		$("#chapterId").hide();
    }else if(adType==2){
   		 $("#h5File").hide();
  		 $("#courseId").show();
  		$("#goodsId").hide();
  		$("#cardId").hide();
  		$("#chapterId").hide();
   	
  	 }else if(adType==3){
  		 $("#h5File").hide();
  		 $("#courseId").hide();
  		$("#goodsId").hide();
  		$("#cardId").hide();
  		$("#chapterId").hide();
   } else if(adType==4){
	   $("#h5File").hide();
		$("#courseId").hide();
		$("#goodsId").show();
		$("#cardId").hide();
		$("#chapterId").hide();
		 
   }else if(adType==5){
	   $("#h5File").hide();
		$("#courseId").hide();
		$("#goodsId").hide();
		$("#cardId").show();
		$("#chapterId").hide();
   }else if(adType==6){
	   $("#h5File").hide();
		$("#courseId").hide();
		$("#goodsId").hide();
		$("#cardId").hide();
		$("#chapterId").show();
  }else{
	  $("#h5File").hide();
		$("#courseId").hide();
		$("#goodsId").hide();
		$("#cardId").hide();
		$("#chapterId").hide();
  }
	
}

</script>
</head>
<body>
		<div class="connect_wrap">
    		<h3 style= "text-align: center;">广告维护</h3>
			<div class="row cl" style="max-width:88%;margin-left:8%;">
			<div class="labelText"></div>
				<form action="<%=basePath%>/adInfo/adInfoEdit" method="post" onsubmit="return checkForm(this)"
					enctype="multipart/form-data">
					<div class="col-sm-4"></div>
	    					<div class="col-sm-4">
	    							<div class="boxs">
												<input type="hidden" name="id" value="${adInfo.id}">
												<input type="text" class="inputBox" placeholder="广告标题" name="adTitle" id="adTitle" value="${adInfo.adTitle}" >
												<input type="text" class="inputBox" placeholder="广告描述" name="adDesc" id="adDesc" value="${adInfo.adDesc}" >
												 <select id="adStatus" name="adStatus" class="selectBox"  >
												  	<option value="">广告状态</option>
												  	<option value="1" ${adInfo.adStatus == 1 ? 'selected="seelcted"' : '' }>正常</option>
										  			<option value="0" ${adInfo.adStatus == 0 ? 'selected="seelcted"' : '' }>下线</option>
												</select>
											    <input type="text" placeholder="开始时间" class="name Wdate inputBox" name="adStartTime" id="adStartTime" value="${adInfo.adStartTime}" 
											    		onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"><br /><br />
				    						    <input type="text" placeholder="结束时间" class="name Wdate inputBox" name="adEndTime" id="adEndTime" value="${adInfo.adEndTime}" 
				    						    		onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"><br /><br />
				    						    <input type="file" class="inputBox" name="imgFile"  value="${adInfo.imgUrl}" placeholder="广告图片"><br /><br />
												<input type="number" class="inputBox" placeholder="广告排序" name="orderNum" value="${adInfo.orderNum}" >
												<select id="adType" name="adType" class="selectBox" onchange="choice()"  >
												  	<option value="">广告类型</option>
												  	<option value="1" ${adInfo.adType == 1 ? 'selected="selected"' : '' }>h5页面</option>
										  			<option value="2" ${adInfo.adType == 2 ? 'selected="selected"' : '' }>视频课程</option>
										  			<option value="3" ${adInfo.adType == 3 ? 'selected="selected"' : '' }>特价秒杀</option>
										  			<option value="4" ${adInfo.adType == 4 ? 'selected="selected"' : '' }>商品</option>
										  			<option value="5" ${adInfo.adType == 5 ? 'selected="selected"' : '' }>课程包</option>
										  			<option value="6" ${adInfo.adType == 6 ? 'selected="selected"' : '' }>课程章节</option>
												</select>
												
												<input type="file" class="inputBox" name="h5File" id="h5File"  value="${adInfo.h5Url}" placeholder="h5链接" >
												 
												<select class="selectBox" name="courseId" id="courseId">
								    				<option value="">----课程编号----</option>
									    			<c:forEach items="${courses}" var="c">
									    				<option value="${c.id}" ${c.id == adInfo.courseId ? 'selected="selected"' : ''}>${c.id}:${c.courseName}</option>
									    			</c:forEach>
					    						</select>
												
												<select class="selectBox" name="goodsId" id="goodsId">
								    				<option value="">----商品编号----</option>
									    			<c:forEach items="${goods}" var="gd">
									    				<option value="${gd.id}" ${gd.id == adInfo.courseId ? 'selected="selected"' : ''}>${gd.id}:${gd.goodsName}</option>
									    			</c:forEach>
					    						</select>
												
												<select class="selectBox" name="cardId" id="cardId">
								    				<option value="-1">----选择课程包----</option>
									    			<c:forEach items="${cards}" var="c">
									    				<option value="${c.id}" ${c.id == adInfo.courseId ? 'selected="selected"' : ''}>${c.id}:${c.cardName}</option>
									    			</c:forEach>
					    						</select>
					    						
					    						
					    						<select class="selectBox" name="chapterId" id="chapterId">
								    				<option value="-1">----选择章节----</option>
									    			<c:forEach items="${chapters}" var="c">
									    				<option value="${c.id}" ${c.id == adInfo.courseId ? 'selected="selected"' : ''}>${c.id}:${c.chapterName}</option>
									    			</c:forEach>
					    						</select>
												
												<input type="submit" value="确定" class="true" />
												<input type="button"  class="false" value="取消" onclick="window.history.go(-1)">
										</div>
								</div>
					</form>
			</div>
	</div>
	
</body>
<script type="text/javascript">

$(function(){
	var adType = document.getElementById('adType').value.trim();   
	if(adType==1){
  		 $("#h5File").show();
 		 $("#courseId").hide();
 		$("#goodsId").hide();
 		$("#cardId").hide();
 		$("#chapterId").hide();
   }else if(adType==2){
  		 $("#h5File").hide();
 		 $("#courseId").show();
 		$("#goodsId").hide();
 		$("#cardId").hide();
 		$("#chapterId").hide();
  	
 	 }else if(adType==3){
 		 $("#h5File").hide();
 		 $("#courseId").hide();
 		$("#goodsId").hide();
 		$("#cardId").hide();
 		$("#chapterId").hide();
  } else if(adType==4){
	   $("#h5File").hide();
		$("#courseId").hide();
		$("#goodsId").show();
		$("#cardId").hide();
		$("#chapterId").hide();
		 
  }else if(adType==5){
	   $("#h5File").hide();
		$("#courseId").hide();
		$("#goodsId").hide();
		$("#cardId").show();
		$("#chapterId").hide();
  }else if(adType==6){
	   $("#h5File").hide();
		$("#courseId").hide();
		$("#goodsId").hide();
		$("#cardId").hide();
		$("#chapterId").show();
 }else{
		 $("#h5File").hide();
		$("#courseId").hide();
		$("#goodsId").hide();
		$("#cardId").hide();
		$("#chapterId").hide();
 }
	 
});


</script>

	 
</html>